package com.hxq.library.controller;

import com.hxq.library.service.IUserService;
import com.hxq.library.service.Impl.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @Author: Ljx
 * @Date: 2021/11/25 14:47
 * @role:
 */
@WebServlet("/payVip")
public class PayVip extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;utf-8");
        HttpSession session = req.getSession();
        String account = (String) session.getAttribute("account");
        IUserService userService = new UserService();
        try {
            int x = userService.payVip(account);
            if (x==0){
                session.setAttribute("vip",0);
            }else if (x==1){
                session.setAttribute("vip",1);
            }else if (x==2){
                session.setAttribute("vip",2);
            }else {
                session.setAttribute("vip",-1);
            }
            resp.sendRedirect(req.getContextPath()+"booleanvip.jsp");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
